package iqq.ui.view.window;

import iqq.ui.widget.TitleComponent;
import iqq.util.SystemUtils;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Window;

import com.alee.laf.rootpane.WebDialog;
import com.alee.utils.SwingUtils;

/**
 * @author ChenZhiHui
 * @create-time 2013-3-7
 */
public class BaseDialog extends WebDialog {

	private TitleComponent titleComponent;
	private Image iconImage;

	public BaseDialog() {
		super();
		init(null);
	}

	public BaseDialog(Frame owner) {
		super(owner);
		init(null);
	}

	public BaseDialog(Frame owner, boolean modal) {
		super(owner, modal);
		init(null);
	}

	public BaseDialog(Frame owner, String title) {
		super(owner, title);
		init(title);
	}

	public BaseDialog(Frame owner, String title, boolean modal) {
		super(owner, title, modal);
		init(title);
	}

	public BaseDialog(Frame owner, String title, boolean modal,
			GraphicsConfiguration gc) {
		super(owner, title, modal, gc);
		init(title);
	}

	public BaseDialog(Dialog owner) {
		super(owner);
		init(null);
	}

	public BaseDialog(Dialog owner, boolean modal) {
		super(owner, modal);
		init(null);
	}

	public BaseDialog(Dialog owner, String title) {
		super(owner, title);
		init(title);
	}

	public BaseDialog(Dialog owner, String title, boolean modal) {
		super(owner, title, modal);
		init(title);
	}

	public BaseDialog(Dialog owner, String title, boolean modal,
			GraphicsConfiguration gc) {
		super(owner, title, modal, gc);
		init(title);
	}

	public BaseDialog(Component owner) {
		super(SwingUtils.getWindowAncestor(owner));
		init(null);
	}

	public BaseDialog(Window owner) {
		super(owner);
		init(null);
	}

	public BaseDialog(Window owner, ModalityType modalityType) {
		super(owner, modalityType);
		init(null);
	}

	public BaseDialog(Window owner, String title) {
		super(owner, title);
		init(title);
	}

	public BaseDialog(Window owner, String title, ModalityType modalityType) {
		super(owner, title, modalityType);
		init(title);
	}

	public BaseDialog(Window owner, String title, ModalityType modalityType,
			GraphicsConfiguration gc) {
		super(owner, title, modalityType, gc);
		init(title);
	}

	/**
	 * 初始化窗口
	 */
	public void init(String title) {
		titleComponent = new TitleComponent(title, this);
		titleComponent.setShowMinimizeButton(false);
		titleComponent.setShowMaximizeButton(false);
		titleComponent.setShowCloseButton(true);
		
		this.setShowTitleComponent(false);
		this.setShowWindowButtons(false);
		this.setShadeWidth(30);
		this.getRootPane().getContentPane()
				.add(titleComponent, BorderLayout.PAGE_START);
		
		/**
		 * 解决LINUX兼容问题
		 */
		if (SystemUtils.isLinux()) {
			this.setUndecorated(true);
		}
	}
	
	/**
	 * @return the iconImage
	 */
	public Image getIconImage() {
		return iconImage;
	}

	/**
	 * @param iconImage the iconImage to set
	 */
	public void setIconImage(Image iconImage) {
		this.iconImage = iconImage;
		super.setIconImage(iconImage);
		titleComponent.setTitleIcon(iconImage);
	}


}
